import random
import string
import hashlib

__all__ = ['random_string', 'random_md5_passwd']


def random_string(str_size):
    return ''.join(random.choice(string.ascii_letters + string.punctuation) for _ in range(str_size))


def random_md5_passwd(passwd=None):
    if passwd is None:
        passwd = random_string(12)
        # print(passwd)
    m = hashlib.md5(passwd.encode(encoding='utf-8'))
    # print(hashlib.md5(passwd.encode(encoding='utf-8')).hexdigest())
    return m.hexdigest()


if __name__ == '__main__':
    print(string.ascii_letters)
    print(string.punctuation)
    print(random_string(11))
    print(random_md5_passwd("admin"))
